class gameHelper {
    private static instance = new gameHelper();
    private constructor() { }
    static getInstance(): gameHelper {
        if (!gameHelper.instance) {
            gameHelper.instance = new gameHelper()
        }
        return this.instance
    }

    Grade: string = 'a';//难度等级
    heroId: string = 'a01';//当前HeroID
    heroDetail: any = null;//当前Hero信息
    levelLength: number = 30;//总关卡数
    selectLevelId: number = 1;//当前选中
    gameJson: any = null;//关卡配置信息

    private _quitTime: Date = null;//上次推出系统时间
    public get quitTime() {
        if (!this._quitTime)
            this._quitTime = JSON.parse(cc.sys.localStorage.getItem("quitTime"));
        return this._quitTime;
    }
    public set quitTime(value: any) {
        this._quitTime = value;
        if (this._quitTime)
            cc.sys.localStorage.setItem("quitTime", JSON.stringify(this._quitTime));
    }
    private _setParams: any = null;//设置信息
    public get mySetParams() {
        if (!this._setParams)
            this._setParams = JSON.parse(cc.sys.localStorage.getItem("mySets"));
        if (!this._setParams)
            this._setParams = [];
        return this._setParams;
    }
    public set mySetParams(value: any) {
        this._setParams = value;
        if (this._setParams)
            cc.sys.localStorage.setItem("mySets", JSON.stringify(this._setParams));
    }
    private _myHeroDetails: any = null;//英雄信息
    public get myHeroDetails() {
        if (!this._myHeroDetails)
            this._myHeroDetails = JSON.parse(cc.sys.localStorage.getItem("myHeros"));
        if (!this._myHeroDetails)
            this._myHeroDetails = [];
        return this._myHeroDetails;
    }
    public set myHeroDetails(value: any) {
        this._myHeroDetails = value;
        if (this._myHeroDetails)
            cc.sys.localStorage.setItem("myHeros", JSON.stringify(this._myHeroDetails));
    }
    private _levelParam: any = null;//闯历史记录
    public get levelParam() {
        if (!this._levelParam)
            this._levelParam = JSON.parse(cc.sys.localStorage.getItem("levelParam"));
        if (!this._levelParam)
            this._levelParam = [];
        return this._levelParam;
    }
    public set levelParam(value: any) {
        this._levelParam = value;
        if (this._levelParam)
            cc.sys.localStorage.setItem("levelParam", JSON.stringify(this._levelParam));
    }
    private _gradeParam: any = null;//经验体力金币值信息
    public get gradeParam() {
        if (!this._gradeParam)
            this._gradeParam = JSON.parse(cc.sys.localStorage.getItem("myGrade"));
        if (!this._gradeParam)
            this._gradeParam = this.newGame();
        return this._gradeParam;
    };
    public set gradeParam(value: any) {
        this._gradeParam = value;
        if (this._gradeParam)
            cc.sys.localStorage.setItem("myGrade", JSON.stringify(this._gradeParam));
    }
    private _skillParam: any = null;//出场技能列表
    public get skillParam() {
        if (!this._skillParam)
            this._skillParam = JSON.parse(cc.sys.localStorage.getItem("mySkill"));
        if (!this._skillParam)
            this._skillParam = { a: [null, null, null, null, null], b: [], new: false };
        return this._skillParam;
    }
    public set skillParam(value: any) {
        this._skillParam = value;
        if (this._skillParam)
            cc.sys.localStorage.setItem("mySkill", JSON.stringify(this._skillParam));
    }
    private newGame(): any {
        let date = {
            exp: 1000,
            ftg: 100,
            ftgMax: 100,
            money: 50,
        }
        return date;
    }
    private _counterParam: any = null;//商城计数器
    public get counterParam() {
        if (!this._counterParam)
            this._counterParam = JSON.parse(cc.sys.localStorage.getItem("myCounter"));
        return this._counterParam;
    }
    public set counterParam(value: any) {
        this._counterParam = value;
        if (this._counterParam)
            cc.sys.localStorage.setItem("myCounter", JSON.stringify(this._counterParam));
    }
    private _skillCounterParam: any = null;//击杀计数器
    public get skillCounterParam() {
        if (!this._skillCounterParam)
            this._skillCounterParam = JSON.parse(cc.sys.localStorage.getItem("mySkillCounter"));
        return this._skillCounterParam;
    }
    public set skillCounterParam(value: any) {
        this._skillCounterParam = value;
        if (this._skillCounterParam)
            cc.sys.localStorage.setItem("mySkillCounter", JSON.stringify(this._skillCounterParam));
    }
    clearLocal() {
        cc.sys.localStorage.removeItem("levelParam");
        cc.sys.localStorage.removeItem("myGrade");
        cc.sys.localStorage.removeItem("myHeros");
        cc.sys.localStorage.removeItem("mySkill");
        cc.sys.localStorage.removeItem("myCounter");
        cc.sys.localStorage.removeItem("mySkillCounter");
        cc.sys.localStorage.removeItem("mySets");
        cc.sys.localStorage.removeItem("quitTime");
    }
    //获取当前挑战关卡信息
    getLevelParam(): any {
        return this.gameJson.Level[this.selectLevelId - 1];
    }
    //获取出场技能列表
    getSkillParam(): string[] {
        let skills = this.getLevelParam();
        let list: string[] = [];
        let _skill: string[] = this.skillParam.a;
        _skill.forEach(element => {
            if (element)
                list.push(element);
        });
        if (skills.SkillHit?.length > 0)
            list = list.concat(skills.SkillHit);
        if (skills.SkillPut?.length > 0)
            list = list.concat(skills.SkillPut);
        if (skills.SkillSelf?.length > 0)
            list = list.concat(skills.SkillSelf);
        return list;
    }
    getHeroPath(): string {
        return "Players/" + this.heroDetail.Prefab;
    }
}
(<any>window).gameHelper = gameHelper;
